package com.yanqu.road.entity.activity.apprentice.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.apprentice.ApprenticeTalentData;
import com.yanqu.road.entity.enums.eOccupationType;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * 玩家门客天资数据
 */
@FieldTypeAnnotation(tableName = "t_u_apprentice_patrons_talent_data", desc = "玩家门客天资数据")
public class ApprenticeUserPatronsTalentData extends DataObject {

    @FieldTypeAnnotation(desc = "玩家ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "门客招募商店类型", select = true, update = true)
    private int mallShopType;

    @FieldTypeAnnotation(desc = "门客IDS")
    private Set<Integer> patronsIds = new HashSet<>();

    @FieldTypeAnnotation(desc = "士-当前天资")
    private long talent1;

    @FieldTypeAnnotation(desc = "农-当前天资")
    private long talent2;

    @FieldTypeAnnotation(desc = "工-当前天资")
    private long talent3;

    @FieldTypeAnnotation(desc = "商-当前天资")
    private long talent4;

    @FieldTypeAnnotation(desc = "侠-当前天资")
    private long talent5;

     @FieldTypeAnnotation(desc = "士-历史总天资")
    private long historyTalent1;

    @FieldTypeAnnotation(desc = "农-历史总天资")
    private long historyTalent2;

    @FieldTypeAnnotation(desc = "工-历史总天资")
    private long historyTalent3;

    @FieldTypeAnnotation(desc = "商-历史总天资")
    private long historyTalent4;

    @FieldTypeAnnotation(desc = "侠-历史总天资")
    private long historyTalent5;

    @FieldTypeAnnotation(desc = "转换过的道具数量")
    private long convertPropNum;

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public ApprenticeUserPatronsTalentData() {
    }

    public ApprenticeUserPatronsTalentData(long userId, int mallShopType, Set<Integer> patronsIds) {
        this.userId = userId;
        this.mallShopType = mallShopType;
        this.patronsIds = patronsIds;
        this.talent1 = 0;
        this.talent2 = 0;
        this.talent3 = 0;
        this.talent4 = 0;
        this.talent5 = 0;
        this.historyTalent1 = 0;
        this.historyTalent2 = 0;
        this.historyTalent3 = 0;
        this.historyTalent4 = 0;
        this.historyTalent5 = 0;
        this.convertPropNum = 0;
        this.createTime = System.currentTimeMillis();
        setInsertOption();
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public int getMallShopType() {
        return mallShopType;
    }
    public void setMallShopType(int mallShopType) {
        if (this.mallShopType != mallShopType) {
            this.mallShopType = mallShopType;
            setOp(DataStatus.Update);
        }
    }

    public Set<Integer> getPatronsIds() {
        return patronsIds;
    }

    public void setPatronsIds(Set<Integer> patronsIds) {
        if (null == patronsIds){
            return;
        }
        if (this.patronsIds == null || !this.patronsIds.equals(patronsIds)) {
            this.patronsIds = patronsIds;
            setOp(DataStatus.Update);
        }
    }

    public long getTalent1() {
        return talent1;
    }
    public void setTalent1(long talent1) {
        if (this.talent1 != talent1) {
            this.talent1 = talent1;
            setOp(DataStatus.Update);
        }
    }

    public long getTalent2() {
        return talent2;
    }
    public void setTalent2(long talent2) {
        if (this.talent2 != talent2) {
            this.talent2 = talent2;
            setOp(DataStatus.Update);
        }
    }

    public long getTalent3() {
        return talent3;
    }
    public void setTalent3(long talent3) {
        if (this.talent3 != talent3) {
            this.talent3 = talent3;
            setOp(DataStatus.Update);
        }
    }

    public long getTalent4() {
        return talent4;
    }
    public void setTalent4(long talent4) {
        if (this.talent4 != talent4) {
            this.talent4 = talent4;
            setOp(DataStatus.Update);
        }
    }

    public long getTalent5() {
        return talent5;
    }
    public void setTalent5(long talent5) {
        if (this.talent5 != talent5) {
            this.talent5 = talent5;
            setOp(DataStatus.Update);
        }
    }

    public long getHistoryTalent1() {
        return historyTalent1;
    }

    public void setHistoryTalent1(long historyTalent1) {
        if (this.historyTalent1 != historyTalent1) {
            this.historyTalent1 = historyTalent1;
            setOp(DataStatus.Update);
        }
    }

    public long getHistoryTalent2() {
        return historyTalent2;
    }

    public void setHistoryTalent2(long historyTalent2) {
        if (this.historyTalent2 != historyTalent2) {
            this.historyTalent2 = historyTalent2;
            setOp(DataStatus.Update);
        }
    }

    public long getHistoryTalent3() {
        return historyTalent3;
    }

    public void setHistoryTalent3(long historyTalent3) {
        if (this.historyTalent3 != historyTalent3) {
            this.historyTalent3 = historyTalent3;
            setOp(DataStatus.Update);
        }
    }

    public long getHistoryTalent4() {
        return historyTalent4;
    }

    public void setHistoryTalent4(long historyTalent4) {
        if (this.historyTalent4 != historyTalent4) {
            this.historyTalent4 = historyTalent4;
            setOp(DataStatus.Update);
        }
    }

    public long getHistoryTalent5() {
        return historyTalent5;
    }

    public void setHistoryTalent5(long historyTalent5) {
        if (this.historyTalent5 != historyTalent5) {
            this.historyTalent5 = historyTalent5;
            setOp(DataStatus.Update);
        }
    }

    public long getConvertPropNum() {
        return convertPropNum;
    }

    public void setConvertPropNum(long convertPropNum) {
          if (this.convertPropNum != convertPropNum) {
            this.convertPropNum = convertPropNum;
            setOp(DataStatus.Update);
        }
    }

    public long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
        if (this.createTime != createTime) {
            this.createTime = createTime;
            setOp(DataStatus.Update);
        }
    }

    /**
     * 添加天资
     * @param type
     * @param talent
     */
    public synchronized void addTalent(int type, long talent) {
        if (eOccupationType.Scholar.getValue() == type) {
            this.talent1 += talent;
            if (talent > 0) {
                this.historyTalent1 += talent;
            }
        } else if (eOccupationType.Farmer.getValue() == type) {
            this.talent2 += talent;
            if (talent > 0) {
                this.historyTalent2 += talent;
            }
        } else if (eOccupationType.Craftsman.getValue() == type) {
            this.talent3 += talent;
            if (talent > 0) {
                this.historyTalent3 += talent;
            }
        } else if (eOccupationType.Businessman.getValue() == type) {
            this.talent4 += talent;
            if (talent > 0) {
                this.historyTalent4 += talent;
            }
        } else if (eOccupationType.Knight.getValue() == type) {
            this.talent5 += talent;
            if (talent > 0) {
                this.historyTalent5 += talent;
            }
        }
        setOp(DataStatus.Update);
    }

    /**
     * 获取天资，根据类型
     * @param type
     * @return
     */
    public long getTalentByType(int type) {
        if (eOccupationType.Scholar.getValue() == type) {
            return talent1;
        } else if (eOccupationType.Farmer.getValue() == type) {
            return talent2;
        } else if (eOccupationType.Craftsman.getValue() == type) {
            return talent3;
        } else if (eOccupationType.Businessman.getValue() == type) {
            return talent4;
        } else if (eOccupationType.Knight.getValue() == type) {
            return talent5;
        }
        return 0;
    }

    /**
     * 获取历史总天资
     * @return
     */
    public long getHistoryAllTalent() {
        return historyTalent1 + historyTalent2 + historyTalent3 + historyTalent4 + historyTalent5;
    }
}
